<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\captcha\Captcha;
/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \common\models\LoginForm */

$this->title = Yii::t('app', 'Login');
$this->params['breadcrumbs'][] = $this->title;

$fieldOptions1 = [
    'options' => ['class' => 'form-group has-feedback'],
    'inputTemplate' => "{input}<span class='glyphicon glyphicon-envelope form-control-feedback'></span>"
];

$fieldOptions2 = [
    'options' => ['class' => 'form-group has-feedback'],
    'inputTemplate' => "{input}<span class='glyphicon glyphicon-lock form-control-feedback'></span>"
];
?>

<div class="login-box">
    <div class="login-logo">
        <a href="#"><b></b>管理后台</a>
    </div>
    <!-- /.login-logo -->
    <div class="login-box-body">
        <p class="login-box-msg">请登录</p>

        <?php $form = ActiveForm::begin(['id' => 'login-form', 'enableClientValidation' => false]); ?>

        <?= $form
            ->field($model, 'username', $fieldOptions1)
            ->label(false)
            ->textInput(['placeholder' => $model->getAttributeLabel('username')]) ?>

        <?= $form
            ->field($model, 'password', $fieldOptions2)
            ->label(false)
            ->passwordInput(['placeholder' => $model->getAttributeLabel('password') ]) ?>
        
		<?php if($yanzhengma){ ?>
		<?= $form->field($model, 'verifyCode', [  
			'options' => ['class' => 'form-group form-group-lg'],  
		 ])->widget(Captcha::className(),[  
			 'options' => ['maxlength' => 4, 'style' => 'width: 190px; padding: 8px;', 'placeholder' => '请输入验证码'],  
			 'template' => "{input} {image}",  
			 'imageOptions' => ['alt' => '验证码','id' => 'login_code', 'src' => '', 'data-api' =>  'site/captcha'  ]]); ?> 
		<?php }?>
        
        <div class="row">
            <div class="col-xs-8">
                <?= $form->field($model, 'rememberMe')->checkbox() ?>
            </div>
            <!-- /.col -->
            <div class="col-xs-4">
                <?= Html::submitButton(Yii::t('app', 'Login'), ['class' => 'btn btn-primary btn-block btn-flat', 'name' => 'login-button']) ?>
            </div>
            <!-- /.col -->
        </div>


        <?php ActiveForm::end(); ?>



    </div>
    <!-- /.login-box-body -->
</div><!-- /.login-box -->
<script>  
    function refreshCode(obj) {
        var url = $(obj).attr('data-api');  
  
        if (url) {  
            $.ajax({  
                url: url + '?refresh',  
                dataType: 'json',  
                type: 'get',  
                success: function(data) {  
                    $(obj).attr('src', data.url);  
                }  
            });  
        }  
      }  
  
    $(function () {  
        refreshCode('#login_code');  
  
        $('#login_code').click(function (event) {  
            event.preventDefault();  //阻止默认行为  
            event.stopPropagation(); //该方法将停止事件的传播，阻止它被分派到其他 Document 节点  
  
            refreshCode(this);  
        });  
  
    });  
</script> 
